﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 多态
{
    class CommissionEmployee:Employee
    {
        private decimal commissionRate;
        private decimal grossSales;

        public CommissionEmployee(string first, string last, string num, decimal rate, decimal gross)
            : base(first, last, num)
        {
            CommissionRate = rate;
            GrossSales = gross;
        }//end constructor CommissionEmployee


        public override string ToString()
        {
            return string.Format("{0}\nthe rate of commission: {1:C}\ngross sales: {2}", base.ToString(), CommissionRate, GrossSales);
        }

        public override decimal Earning()
        {
            return CommissionRate * GrossSales;
        }

        public decimal CommissionRate
        {
            get
            {
                return commissionRate;
            }
            set
            {
                commissionRate = ((value > 0) && (value < 1) ? value : 0);
            }
        }

        public decimal GrossSales
        {
            get
            {
                return grossSales;
            }
            set
            {
                grossSales = (value >= 0) ? value : 0;
            }
        }
    }//end class Employee
}
